FlashTunes Sample Application
FlashTunes is an advanced Macromedia Flash sample application (see Figure 1) that takes advantage of many technologies Macromedia offers to allow you to access Apple iTunes RSS feeds. The application demonstrates the use of the following:
- ActionScript 2.0
- Creating custom ActionScript 2.0 classes
- Using Macromedia Flash MX 2004 components
- Using the EventDispatcher class
- Using external CSS style sheets
Figure 1. The Commerce Search sample application screen
Through this application, users are able to access and preview five of the most popular iTunes RSS feeds. These feeds provide users with information about the song or album specified in the feed. With an intermediate knowledge of ActionScript, developers can modify this application and add or remove feeds that they can generate by visiting the iTunes Music Store RSS Feed Generator.
Running the FlashTunes Application
To run FlashTunes, all you need is the app.swf Flash file and the styles.css style sheet. Because the style sheet is loaded at runtime, it has to be available to the application. The style sheet should always be at the same directory level as app.swf. Also, you need to make sure that Flash 7 Player, which comes with Flash MX 2004, is installed on the system running the application. If all of these requirements are met, double-click app.swf.
Compiling the FlashTunes Application
To compile FlashTunes, you must have Flash MX 2004 Professional installed on your system. Open the tunes.flp Flash Project file. Select Window > Project to open the Project window (see Figure 2), which displays all the custom class files that are needed in the application. To compile and run this project, click on the Test Project button in the Project window.
Figure 2. The Project window
Modifying the Application
There are many ways to extend FlashTunes. Let's look two areas that will be easy to start with.
One way to modify the FlashTunes application is to make use of the new ability in Flash MX 2004 to load external CSS style sheets. In the root directory, you will find a file called styles.css. This file contains all the styles used by the Detail description area in the FlashTunes application. Because the style sheet is loaded at runtime, you can edit the style sheet without having to recompile the application.
To make changes to the style sheet:
- Open the style sheet in Dreamweaver MX 2004 or your favorite text editor.
- Make changes to the styles
- Close and reopen app.swf.
You should now see your changes to the style sheet appear in the Detail area of the FlashTunes application.
To accomplish the loading of the style sheet in ActionScript, all that's needed are a few lines of code to load the style sheet and then associate it with the description TextArea component:
// Let's import the StyleSheet class
import TextField.StyleSheet;
// Create a new instance of the StyleSheet
var style_sheet = new TextField.StyleSheet();
// Let's create a way back to the current scope
style_sheet.scope = this;
// Define onLoad handler; this is called when the
// style sheet is loaded and parsed
style_sheet.onLoad = function(success) {
if (success) {
// If the style sheet loaded without error,
// then assign it to the description Text Area.
this.scope.description_txa.styleSheet = this;
}
};
// Load the style sheet
style_sheet.load("styles.css");
The other way to modify the application easily is to add and delete custom feeds to the application. FlashTunes makes use of the recently released Apple iTunes Music Store RSS Feeds. Generate custom feeds by clicking here and editing the feeds within the application:
- Visit the iTunes Music Store RSS Feed Generator.
- Select your options and click Generate.
- Copy the feed's URL in the RSS Feed URL text field.
- Open the com/macromedia/drk6/tunes/TunesModel.as ActionScript file.
- On line 32 you will see an array that holds all the default feeds that are available to users.
- Either replace or add a new object to the array. The object will include a label field (the name that will be displayed for the feed) and a data field (the URL that you copied from the iTunes Music Store RSS Feed Generator in steps 1–3).
- Recompile the application as described in the earlier "Compiling the FlashTunes Application" section.
What's Next?
Now that you can run the application, feel free to take it apart! To learn more about the other technologies used to develop FlashTunes, visit the Macromedia Developer Center. The ActionScript Resources section is a great place to start.